<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: tax_rates.php 123 2013-09-21 12:11:18Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 123 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-21 12:11:18 +0000 (Sat, 21 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

require('includes/application_top.php');

if ($_GET['action']) {
	switch ($_GET['action']) {
		case 'insert':
			$tax_zone_id = $_POST['tax_zone_id'];
			$tax_class_id = $_POST['tax_class_id'];
			$tax_rate = $_POST['tax_rate'];
			$tax_description = $_POST['tax_description'];
			$tax_priority = $_POST['tax_priority'];
			$date_added = $_POST['date_added'];

			$db->db_query("INSERT INTO
								".TABLE_TAX_RATES."
								(tax_zone_id, tax_class_id, tax_rate, tax_description, tax_priority, date_added)
							VALUES
								(".$db->db_prepare($tax_zone_id).", ".$db->db_prepare($tax_class_id).", ".$db->db_prepare($tax_rate).", ".$db->db_prepare($tax_description).", ".$db->db_prepare($tax_priority).", NOW())");
			redirect(href_link(FILENAME_TAX_RATES));
		break;

		case 'save':
			$tax_rates_id = $_GET['tID'];
			$tax_zone_id = $_POST['tax_zone_id'];
			$tax_class_id = $_POST['tax_class_id'];
			$tax_rate = $_POST['tax_rate'];
			$tax_description = $_POST['tax_description'];
			$tax_priority = $_POST['tax_priority'];
			$last_modified = $_POST['last_modified'];

			$db->db_query("UPDATE
								".TABLE_TAX_RATES."
							SET
								tax_rates_id = ".$db->db_prepare($tax_rates_id).",
								tax_zone_id = ".$db->db_prepare($tax_zone_id).",
								tax_class_id = ".$db->db_prepare($tax_class_id).",
								tax_rate = ".$db->db_prepare($tax_rate).",
								tax_description = ".$db->db_prepare($tax_description).",
								tax_priority = ".$db->db_prepare($tax_priority).",
								last_modified = NOW()
							WHERE
								tax_rates_id = ".$db->db_prepare($tax_rates_id));
			redirect(href_link(FILENAME_TAX_RATES, 'page='.$_GET['page'].'&tID='.$tax_rates_id));
		break;

		case 'deleteconfirm':
			$tax_rates_id = $_GET['tID'];

			$db->db_query("DELETE FROM ".TABLE_TAX_RATES." WHERE tax_rates_id = ".$db->db_prepare($tax_rates_id));
			redirect(href_link(FILENAME_TAX_RATES, 'page='.$_GET['page']));
		break;
	}
}
require(DIR_WS_INCLUDES.'metatag.php'); ?>
</head>
<body>
<?php require(DIR_WS_INCLUDES.'header.php'); ?>
<div id="wrapper">
<table class="outerTable" cellspacing="0" cellpadding="0">
	<tr>
	    <td class="columnLeft2" width="<?php echo BOX_WIDTH; ?>" valign="top">
			<?php require(DIR_WS_INCLUDES.'column_left.php'); ?>
		</td>
	    <td class="boxCenter" valign="top">
		<table border="0" width="100%" cellspacing="0" cellpadding="2">
			<tr>
				<td>
					<table class="table_pageHeading" width="100%" cellspacing="0" cellpadding="0">
						<tr>
							<td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
						</tr>
					</table>
				</td>
			</tr>
		<tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td valign="top">
			<table border="0" width="100%" cellspacing="0" cellpadding="2" class="dataTable">
              <tr class="dataTableHeadingRow">
                <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_TAX_RATE_PRIORITY; ?></td>
                <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_TAX_CLASS_TITLE; ?></td>
                <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_ZONE; ?></td>
                <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_TAX_RATE; ?></td>
                <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_ACTION; ?>&nbsp;</td>
              </tr>
			<?php
			  $rates = $db->db_query("SELECT 
						  				r.tax_rates_id, 
						  				z.geo_zone_id, 
						  				z.geo_zone_name, 
						  				tc.tax_class_title, 
						  				tc.tax_class_id, 
						  				r.tax_priority, 
						  				r.tax_rate, 
						  				r.tax_description, 
						  				r.date_added, 
						  				r.last_modified 
						  			FROM 
						  				".TABLE_TAX_CLASS." tc, 
						  				".TABLE_TAX_RATES." r 
						  				LEFT JOIN 
						  					".TABLE_GEO_ZONES." z 
						  					ON r.tax_zone_id = z.geo_zone_id 
						  			WHERE 
						  				r.tax_class_id = tc.tax_class_id");

			  while(!$rates->EOF) {
			    if (((!$_GET['tID']) || (@$_GET['tID'] == $rates->fields['tax_rates_id'])) && (!$trInfo) && (substr($_GET['action'], 0, 3) != 'new'))
			      $trInfo = new objectInfo($rates->fields);

			    if ( (is_object($trInfo)) && ($rates->fields['tax_rates_id'] == $trInfo->tax_rates_id) ) {
			      echo '<tr class="dataTableRowSelected" onmouseover="this.style.cursor=\'hand\'" onclick="document.location.href=\''.href_link(FILENAME_TAX_RATES, 'page='.$_GET['page'].'&tID='.$trInfo->tax_rates_id.'&action=edit').'\'">'."\n";
			    } else {
			      echo '<tr class="dataTableRow" onmouseover="this.className=\'dataTableRowOver\';this.style.cursor=\'hand\'" onmouseout="this.className=\'dataTableRow\'" onclick="document.location.href=\''.href_link(FILENAME_TAX_RATES, 'page='.$_GET['page'].'&tID='.$rates->fields['tax_rates_id']).'\'">'."\n";
			    }
			?>
                <td class="dataTableContent"><?php echo $rates->fields['tax_priority']; ?></td>
                <td class="dataTableContent"><?php echo $rates->fields['tax_class_title']; ?></td>
                <td class="dataTableContent"><?php echo $rates->fields['geo_zone_name']; ?></td>
                <td class="dataTableContent"><?php echo display_tax_value($rates->fields['tax_rate']); ?>%</td>
                <td class="dataTableContent" align="right"><?php if ( (is_object($trInfo)) && ($rates->fields['tax_rates_id'] == $trInfo->tax_rates_id) ) { echo image(DIR_WS_IMAGES.'icon_arrow_right.gif', ''); } else { echo '<a href="'.href_link(FILENAME_TAX_RATES, 'page='.$_GET['page'].'&tID='.$rates->fields['tax_rates_id']).'">'.image(DIR_WS_IMAGES.'icon_info.gif', IMAGE_ICON_INFO).'</a>'; } ?>&nbsp;</td>
			<?php
				echo '</tr>';
				$rates->MoveNext();
			  }
			?>
            </table>
			<table border="0" width="100%" cellspacing="0" cellpadding="2">
			<?php
			if (!$_GET['action']) {
			?>
		  <tr>
			<td colspan="5" align="right"><?php echo '<a class="button" onClick="this.blur();" href="'.href_link(FILENAME_TAX_RATES, 'page='.$_GET['page'].'&action=new').'">'.BUTTON_NEW_TAX_RATE.'</a>'; ?></td>
		  </tr>
			<?php
			}
			?>
		</table>
	</td>
		<?php
		  $heading = array();
		  $contents = array();
		  switch ($_GET['action']) {
		    case 'new':
		      $heading[] = array('text' => '<b>'.TEXT_INFO_HEADING_NEW_TAX_RATE.'</b>');

		      $contents = array('form' => draw_form('rates', FILENAME_TAX_RATES, 'page='.$_GET['page'].'&action=insert'));
		      $contents[] = array('text' => TEXT_INFO_INSERT_INTRO);
		      $contents[] = array('text' => '<br />'.TEXT_INFO_CLASS_TITLE.'<br />'.tax_classes_pull_down('name="tax_class_id" style="font-size:10px"'));
		      $contents[] = array('text' => '<br />'.TEXT_INFO_ZONE_NAME.'<br />'.geo_zones_pull_down('name="tax_zone_id" style="font-size:10px"'));
		      $contents[] = array('text' => '<br />'.TEXT_INFO_TAX_RATE.'<br />'.draw_input_field('tax_rate'));
		      $contents[] = array('text' => '<br />'.TEXT_INFO_RATE_DESCRIPTION.'<br />'.draw_input_field('tax_description'));
		      $contents[] = array('text' => '<br />'.TEXT_INFO_TAX_RATE_PRIORITY.'<br />'.draw_input_field('tax_priority'));
		      $contents[] = array('align' => 'center', 'text' => '<br /><button type="submit" class="button" onclick="this.blur();">'.BUTTON_INSERT.'</button>&nbsp;<a class="button" onClick="this.blur();" href="'.href_link(FILENAME_TAX_RATES, 'page='.$_GET['page']).'">'.BUTTON_CANCEL.'</a>');
		      break;

		    case 'edit':
		      $heading[] = array('text' => '<b>'.TEXT_INFO_HEADING_EDIT_TAX_RATE.'</b>');

		      $contents = array('form' => draw_form('rates', FILENAME_TAX_RATES, 'page='.$_GET['page'].'&tID='.$trInfo->tax_rates_id .'&action=save'));
		      $contents[] = array('text' => TEXT_INFO_EDIT_INTRO);
		      $contents[] = array('text' => '<br />'.TEXT_INFO_CLASS_TITLE.'<br />'.tax_classes_pull_down('name="tax_class_id" style="font-size:10px"', $trInfo->tax_class_id));
		      $contents[] = array('text' => '<br />'.TEXT_INFO_ZONE_NAME.'<br />'.geo_zones_pull_down('name="tax_zone_id" style="font-size:10px"', $trInfo->geo_zone_id));
		      $contents[] = array('text' => '<br />'.TEXT_INFO_TAX_RATE.'<br />'.draw_input_field('tax_rate', $trInfo->tax_rate));
		      $contents[] = array('text' => '<br />'.TEXT_INFO_RATE_DESCRIPTION.'<br />'.draw_input_field('tax_description', $trInfo->tax_description));
		      $contents[] = array('text' => '<br />'.TEXT_INFO_TAX_RATE_PRIORITY.'<br />'.draw_input_field('tax_priority', $trInfo->tax_priority));
		      $contents[] = array('align' => 'center', 'text' => '<br /><button type="submit" class="button" onclick="this.blur();">'. BUTTON_UPDATE.'</button>&nbsp;<a class="button" onClick="this.blur();" href="'.href_link(FILENAME_TAX_RATES, 'page='.$_GET['page'].'&tID='.$trInfo->tax_rates_id).'">'.BUTTON_CANCEL.'</a>');
		      break;

		    case 'delete':
		      $heading[] = array('text' => '<b>'.TEXT_INFO_HEADING_DELETE_TAX_RATE.'</b>');

		      $contents = array('form' => draw_form('rates', FILENAME_TAX_RATES, 'page='.$_GET['page'].'&tID='.$trInfo->tax_rates_id .'&action=deleteconfirm'));
		      $contents[] = array('text' => TEXT_INFO_DELETE_INTRO);
		      $contents[] = array('text' => '<br /><b>'.$trInfo->tax_class_title.' '.number_format($trInfo->tax_rate, TAX_DECIMAL_PLACES).'%</b>');
		      $contents[] = array('align' => 'center', 'text' => '<br /><input type="submit" class="button" onClick="this.blur();" value="'.BUTTON_DELETE.'"/>&nbsp;<a class="button" onClick="this.blur();" href="'.href_link(FILENAME_TAX_RATES, 'page='.$_GET['page'].'&tID='.$trInfo->tax_rates_id).'">'.BUTTON_CANCEL.'</a>');
		      break;

		    default:
		      if (is_object($trInfo)) {
		        $heading[] = array('text' => '<b>'.$trInfo->tax_class_title.'</b>');
		        $contents[] = array('align' => 'center', 'text' => '<a class="button" onClick="this.blur();" href="'.href_link(FILENAME_TAX_RATES, 'page='.$_GET['page'].'&tID='.$trInfo->tax_rates_id.'&action=edit').'">'.BUTTON_EDIT.'</a> <a class="button" onClick="this.blur();" href="'.href_link(FILENAME_TAX_RATES, 'page='.$_GET['page'].'&tID='.$trInfo->tax_rates_id.'&action=delete').'">'.BUTTON_DELETE.'</a>');
		        $contents[] = array('text' => '<br />'.TEXT_INFO_DATE_ADDED.' '.date_short($trInfo->date_added));
		        $contents[] = array('text' => ''.TEXT_INFO_LAST_MODIFIED.' '.date_short($trInfo->last_modified));
		        $contents[] = array('text' => '<br />'.TEXT_INFO_RATE_DESCRIPTION.'<br />'.$trInfo->tax_description);
		      }
		      break;
		  }

		  if ( (not_null($heading)) && (not_null($contents)) ) {
		    echo '<td width="25%" class="border" valign="top">'."\n";
		    $box = new box;
		    echo $box->infoBox($heading, $contents);
		    echo '</td>'."\n";
		  }
		?>
          </tr>
        </table></td>
      </tr>
    </table></td>
</tr>
</table>
</div>
<?php require(DIR_WS_INCLUDES.'footer.php'); ?>
</body>
</html>
<?php require(DIR_WS_INCLUDES.'application_bottom.php'); ?>